//
//  LCMainScrollView.m
//  TheLCNews
//
//  Created by apple on 15/12/1.
//  Copyright © 2015年 LC. All rights reserved.
//

#import "LCMainScrollView.h"
#import "LCScrollModel.h"
@implementation LCMainScrollView


#pragma mark 初始化方法
- (instancetype)initWithFrame:(CGRect)frame index:(NSInteger)index modelArray:(NSMutableArray *)array{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame  = frame;
        self.contentSize = CGSizeMake( KWIDTH * index, 0);      // 设置轮播多少页
        self.contentOffset = CGPointMake(0, 0);                      // 初始执行页
        self.pagingEnabled = YES;                                    // 是否按页浏览
        self.bounces = NO;
        
        // 把传过来的数组用创建的属性数组接收。
        self.array = array;
        
        // 自动轮播
        //        [self createTimer];
        
        for (NSInteger i = 0; i < index; i++) {
            // 把传入的数据转化成model
            LCScrollModel *model = array[i];
            
            
            
            
            // imageview图片
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(KWIDTH * i, 0, KWIDTH, frame.size.height)];
            [self addSubview:imageView];
            [imageView sd_setImageWithURL:[NSURL URLWithString:model.thumbnail] placeholderImage:[UIImage imageNamed:@"zanweitu.png"]];
            
            // label标题
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(KWIDTH * i, frame.size.height - KHEIGHT / 26.68, KWIDTH, KHEIGHT / 26.68)];
            [self addSubview:label];
            label.backgroundColor = [UIColor clearColor];
            label.textColor = [UIColor whiteColor];
            label.font = [UIFont systemFontOfSize:14.];
            label.text = [NSString stringWithFormat:@"    %@", model.title];
            
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, label.frame.size.width, label.frame.size.height)];
            [label addSubview:view];
            view.backgroundColor = [UIColor blackColor];
            view.alpha = 0.5;
        }
    }
    return self;
}








/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
